/*  Created By : Ei Han
 * Date  : 18th OCT 2010
 * 
 */

package edu.nus.iss.t5.jass.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ConvolveOp;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import edu.nus.iss.t5.jass.entity.JobAdvertisement;
import edu.nus.iss.t5.jass.exception.DAOException;
import edu.nus.iss.t5.jass.controller.*;

public class DeletePanel extends JPanel implements ActionListener{

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    JPanel titlePanel;
    JLabel titleLable;
    JPanel dataPanel;//data Object may replace here
    JLabel jobTitle;
    JLabel jobDesc;
    JLabel jobTechSkills;
    JLabel jobMgmtSkills;
    JLabel jobyearExp;
    JLabel maxSalary;
    JLabel minSalary;
    JLabel startDate;
    JLabel jobOwner;
    JLabel compDesc;
    JLabel postStatus;
    JLabel advCreateDate;
    JLabel advModifyDate;
    JPanel buttonPanel;
    JButton deleteButton;
    JButton closeButton;
    JPanel allPanel;
    final static boolean RIGHT_TO_LEFT = false;
    Toolkit tk = Toolkit.getDefaultToolkit();
    int xSize = ((int) tk.getScreenSize().getWidth());
    
    JobAdvertisement jad;
    
    public DeletePanel(){
    	
    }
    
    /**
   * Constructor for DeletePanel
   * @param JobAdvertisement object
   */
    public DeletePanel(JobAdvertisement adv) {
    	jad=adv;
        titlePanel = new JPanel();
        titlePanel.setVisible(true);
        titlePanel.setPreferredSize(new Dimension(xSize - 430, 25));
        titlePanel.setBorder(
                new TitledBorder(new LineBorder(Color.GRAY, 1, false), "Delete Job Advertisement Here", TitledBorder.LEFT, TitledBorder.BELOW_TOP));
        this.add(titlePanel, BorderLayout.NORTH);
        dataPanel = new JPanel();

        buttonPanel = new JPanel();

        deleteButton = new JButton("Delete");
        closeButton = new JButton("Close");
        //closeButton.addActionListener(this);
        buttonPanel.add(deleteButton, BorderLayout.EAST);
        buttonPanel.add(closeButton, BorderLayout.WEST);

        //it may delete after adding setter getter methods;
        jobTitle =      new JLabel("Job Title             :");
        jobDesc =       new JLabel("Job Description       :");
        jobTechSkills = new JLabel("Technical Skills      :");
        jobMgmtSkills = new JLabel("Management Skills     :");
        jobyearExp =    new JLabel("Year of Experience    :");
        maxSalary =     new JLabel("Maximum Salary        :");
        minSalary =     new JLabel("Minimum Salary        :");
        startDate =     new JLabel("Start Date Joined     :");
        jobOwner =      new JLabel("Owner                 :");
        compDesc =      new JLabel("Company Description   :");
        postStatus =    new JLabel("Status                :");
        advCreateDate = new JLabel("Created Date          :");
        advModifyDate = new JLabel("Modified Date         :");

        addComponentsToPane(new JPanel());

        this.add(allPanel);
    }

   
    public void addComponentsToPane(Container pane) {

        if (RIGHT_TO_LEFT) {
            pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        }

        pane.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        // first row below
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 0;
        pane.add(jobTitle, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 0;

        pane.add(new JLabel(jad.getTitle()), c);//data will come here by Object

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 0;
        pane.add(new JLabel(""), c);

        // second row below
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 1;
        pane.add(jobDesc, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 1;
        pane.add(new JLabel(jad.getJobDescription()), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 1;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 2;
        pane.add(jobTechSkills, c);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 2;
        pane.add(new JLabel(jad.getTechnicalSkills()), c);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 2;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 3;
        pane.add(jobMgmtSkills, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 3;
        pane.add(new JLabel(jad.getManagementSkills()), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 3;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 4;
        pane.add(jobyearExp, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 4;
        pane.add(new JLabel(String.valueOf(jad.requiredWorkingExperience)), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 4;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 5;
        pane.add(maxSalary, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 5;
        pane.add(new JLabel(String.valueOf(jad.getSalaryMax())), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 5;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 6;
        pane.add(minSalary, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 6;
        pane.add(new JLabel(String.valueOf(jad.getSalaryMin())), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 2;
        c.gridy = 6;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 7;
        pane.add(startDate, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 7;
        pane.add(new JLabel(String.valueOf(jad.getRequiredStartDate())), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 0;
        c.gridy = 7;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 8;
        pane.add(jobOwner, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 8;
        pane.add(new JLabel(jad.getOwner()), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 0;
        c.gridy = 8;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 9;
        pane.add(compDesc, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 9;
        pane.add(new JLabel(jad.getCompany()), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 0;
        c.gridy = 9;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 10;
        pane.add(postStatus, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 10;
        pane.add(new JLabel(jad.toStringStatus()), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 0;
        c.gridy = 10;
        pane.add(new JLabel(""), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 11;
        pane.add(advModifyDate, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 1;
        c.gridy = 11;
        pane.add(new JLabel(String.valueOf(jad.getModifyDate())), c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridx = 0;
        c.gridy = 11;
        pane.add(new JLabel(""), c);

        pane.setVisible(true);
        pane.setPreferredSize(new Dimension(xSize - 500, 300));
        pane.setBackground(Color.WHITE);
        dataPanel.add(pane);

        allPanel = new JPanel(new BorderLayout());
        allPanel.add(titlePanel, BorderLayout.NORTH);
        allPanel.add(dataPanel, BorderLayout.CENTER);
        allPanel.add(buttonPanel, BorderLayout.SOUTH);

    }
    
    /**
     * Method for Deleting JobAdvertisement    
     */
   public void DeleteAdvertisement()
   {
	   try {
		JobAdvertisementController.getInstance().confirmDeleteJobAdvertisement(jad);
	} catch (DAOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
  	 JOptionPane.showMessageDialog(this,"Successfully Deleted Advertisement");	   
   }

    public void actionPerformed(ActionEvent e) {


    }
}
